home *** CD-ROM | disk | FTP | other *** search
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
- /* */
- /* Prototype HP15C Calculator */
- /* James C. Ullrey */
- /* INRESCO */
- /* © 1990 */
- /* Version 13.97a */
- /* */
- /* DORK SEGMENT */
- /* */
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
-
-
- /*****************************************************************/
- /* I N C L U D E S
- /*****************************************************************/
-
- #ifndef __C14__
- #include "PredatorPrey.h"
- #endif
- #include "calc_dork.h"
- #include "calc_update.h"
- #include "calc_draw_object.h"
- #include "calc_handlebutton.h"
-
- /********************************************************************
- /* G L O B A L V A R I A B L E D E C L A R A T I O N S
- /********************************************************************/
-
- extern WindowPtr lastPtr;
- extern Rect gFirstCalcIcon,gSecondCalcIcon,gThirdCalcIcon;
- extern Rect gFourthCalcIcon,gFifthCalcIcon,gSixthCalcIcon;
- extern WindowPtr preyPtr;
-
- /*****************************************************************/
- /* P R O T O T Y P E S
- /*****************************************************************/
-
-
- DialogPtr GetStretchDialog (void);
- DialogPtr GetRotateDialog (void);
- void Do_Stretch (WindowPtr wPtr);
-
- void MatrixTimesVector (
- double_t transMat[4][4],
- double_t *vector[]
- );
- void MatTimesMat (
- double_t rotMat[4][4],
- double_t oRotMat[4][4],
- /*double *rRotMat[4][4],*/
- double_t *qRotMat[]
- );
-
- void GetSinCos (
- double_t delQ,
- double_t *sinQ,
- double_t *cosQ
- );
-
-
- /*****************************************************************/
- /*****************************************************************/
- /* */
- /* R O U T I N E S */
- /* */
- /*****************************************************************/
- /*****************************************************************/
-
- void dork_seg() {} /* for reference in "UnloadSeg()" calls */
-
-
- /*********************** GetStretchDialog ************************/
- DialogPtr GetStretchDialog(void)
- {
- DialogPtr dPtr;
- GrafPtr oldPort;
-
- dPtr = GetNewDialog(BASE_RES_ID+20, NIL, (WindowPtr)-1L);
- if(dPtr == NIL)
- {
- GetPort(&oldPort );
- #ifdef powerc
- StopAlert(NO_STRETCH_DIALOG, (UniversalProcPtr)NIL);
- #else
- StopAlert(NO_STRETCH_DIALOG, NIL);
- #endif /* powerc */
- SetPort( oldPort );
- return(NIL);
- }
- return(dPtr);
- }
-
- /*********************** GetRotateDialog *************************/
- DialogPtr GetRotateDialog(void)
- {
- DialogPtr dPtr;
- GrafPtr oldPort;
-
- dPtr = GetNewDialog(BASE_RES_ID+25, NIL, (WindowPtr)-1L);
- if(dPtr == NIL)
- {
- GetPort(&oldPort );
- #ifdef powerc
- StopAlert(NO_ROTATE_DIALOG, (UniversalProcPtr)NIL);
- #else
- StopAlert(NO_ROTATE_DIALOG, NIL);
- #endif /* powerc */
- SetPort( oldPort );
- return(NIL);
- }
- return(dPtr);
- }
-
- /*********************** HandleGraphChoice ***********************/
- /************************** Do_Stretch ***************************/
- void Do_Stretch(WindowPtr wPtr)
- {
- short index,i,j;
- long inc;
- long ticktime;
- WObjsHandle w_objs_hndl;
- objectDescr the_object;
- Boolean spec;
-
- spec = FALSE;
-
- w_objs_hndl = (WObjsHandle)GetWRefCon(wPtr);
-
- for( index = 0; index < MAX_OBJECTS; index++)
- {
- the_object = (**w_objs_hndl).object[index];
- if((the_object.type == CUBE_OBJ) && (the_object.selected == TRUE))
- {
- for(i = 1;i <= 9; i++)
- {
- switch(i)
- {
- case 1:
- case 9:
- inc = 1;
- break;
- case 2:
- case 8:
- inc = 2;
- break;
- case 3:
- case 7:
- inc = 4;
- break;
- case 4:
- case 6:
- inc = 8;
- break;
- case 5:
- inc = 10;
- break;
-
- }
- for(j = 0; j<=7; j++)
- {
- switch(j)
- {
- case 1:
- case 2:
- case 5:
- case 6:
- (**w_objs_hndl).object[index]._3dPt[j].x_point += inc;
- break;
- case 0:
- case 3:
- case 4:
- case 7:
- (**w_objs_hndl).object[index]._3dPt[j].x_point -= inc;
- break;
- }
- }
- EraseRect(&(**w_objs_hndl).object[index].bounds);
- SetRect(&(**w_objs_hndl).object[index].bounds,
- (**w_objs_hndl).object[index].bounds.left - (inc /*+ 1*/),
- (**w_objs_hndl).object[index].bounds.top,
- (**w_objs_hndl).object[index].bounds.right + (inc /*+ 1*/),
- (**w_objs_hndl).object[index].bounds.bottom);
-
- /*SetRect(&(**w_objs_hndl).object[index].bounds,+(inc+1),0);*/
- draw_object(wPtr,index, spec);
- Delay (60L, &ticktime);
- }
- }
- }
- }
-
-
- /************************** Do_Rotate ****************************/
- void Do_Rotate(WindowPtr wPtr,double_t delX,double_t delY,double_t delZ,Boolean useCalc)
- /* when coming from a mouseclick in */
- /* gRotateBox, wPtr is LastPtr */
- {
- Boolean spec;
- Point offset;
- Rect obj_rect;
- short myItemHit;
- short index;
- short i,j,k;
- short limit;
- short resultRow;
- short resultCol;
- short sourceCol;
- short yBase;
- short xBase;
- short zBase;
- short yNum;
- short xNum;
- short zNum;
-
- long minX,maxX,minY,maxY,minZ,maxZ;
- long tempX,tempY,tempZ;
- long newX,newY,newZ;
- WObjsHandle w_objs_hndl;
- objectDescr the_object;
-
- double_t transMat[4][4];
- double_t rotMat[4][4];
- double_t rRotMat[4][4];
-
- double_t vector[4];
- double_t newVect[4];
-
- double_t sinX,cosX,sinY,cosY,sinZ,cosZ;
-
- GrafPtr oldPort;
- Boolean notFront;
-
- for(i = 0;i <= 3;i++)
- {
- for(j = 0;j <= 3;j++)
- {
- if(i == j)
- {
- transMat[i][j] = 1;
- rotMat[i][j] = 1;
- }
- else
- {
- transMat[i][j] = 0;
- rotMat[i][j] = 0;
- }
- }
- }
- vector[3] = 1;
-
- if(delX == 0 && delY == 0 && delZ == 0)
- {
- return;
- }
-
- if(delX != 0)
- {
- GetSinCos(delX,&sinX,&cosX);
- rotMat[1][1] = cosX;
- rotMat[1][2] = sinX;
- rotMat[2][1] = -sinX;
- rotMat[2][2] = cosX;
- }
- else if(delY != 0)
- {
- GetSinCos(delY,&sinY,&cosY);
- rotMat[0][0] = cosY;
- rotMat[0][2] = sinY;
- rotMat[2][0] = -sinY;
- rotMat[2][2] = cosY;
- }
- else if(delZ != 0)
- {
- GetSinCos(delZ,&sinZ,&cosZ);
- rotMat[0][0] = cosZ;
- rotMat[0][1] = sinZ;
- rotMat[1][0] = -sinZ;
- rotMat[1][1] = cosZ;
- }
-
- w_objs_hndl = (WObjsHandle)GetWRefCon(wPtr);
-
- for( index = 0; index < MAX_OBJECTS; index++)
- {
- the_object = (**w_objs_hndl).object[index];
- if(((the_object.type == CUBE_OBJ) || (the_object.type == HOUSE_OBJ)) && (the_object.selected == TRUE))
- {
- minZ = (**w_objs_hndl).object[index]._3dPt[0].z_point;
- maxZ = (**w_objs_hndl).object[index]._3dPt[0].z_point;
- switch(the_object.type)
- {
- case 4:
- limit = 7;
- break;
- case 5:
- if((**w_objs_hndl).object[index].armed == TRUE) limit = 21;
- else limit = 17;
- break;
- }
- for(i = 1; i <= limit; i++)
- {
- tempZ = (**w_objs_hndl).object[index]._3dPt[i].z_point;
- if(tempZ < minZ)
- {
- minZ = tempZ;
- }
- if(tempZ > maxZ)
- {
- maxZ = tempZ;
- }
- }
- minX = (**w_objs_hndl).object[index].bounds.left/* - offset.h*/;
- maxX = (**w_objs_hndl).object[index].bounds.right/* - offset.h*/;
- minY = (**w_objs_hndl).object[index].bounds.top/* - offset.v*/;
- maxY = (**w_objs_hndl).object[index].bounds.bottom/* - offset.v*/;
-
- newX = minX + (maxX - minX)/2; /* X-midpoint */
- newY = minY + (maxY - minY)/2; /* Y-midpoint */
- newZ = minZ + (maxZ - minZ)/2; /* Z-midpoint */
-
- if(delX != 0)
- {
- rotMat[1][3] = newY * (1 - cosX) - newZ * sinX;
- rotMat[2][3] = newZ * (1 - cosX) + newY * sinX;
- }
- else if(delY != 0)
- {
- rotMat[0][3] = newX * (1 - cosY) - newZ * sinY;
- rotMat[2][3] = newZ * (1 - cosY) + newX * sinY;
- }
- else if(delZ != 0)
- {
- rotMat[0][3] = newX * (1 - cosZ) - newY * sinZ;
- rotMat[1][3] = newY * (1 - cosZ) + newX * sinZ;
- }
-
- for(i = 0;i <= 3;i++) /* initialize rRotMat */
- {
- for(j = 0;j <= 3;j++)
- {
- rRotMat[i][j] = 0;
- }
- }
-
- for(i = 0;i <= 3;i++)
- {
- for(j = 0;j <= 3;j++)
- {
- for(k = 0;k <= 3;k++)
- {
- rRotMat[i][j] += rotMat[i][k] * (**w_objs_hndl).object[index].rotHist[k][j].rotElem;
- }
- }
- }
- for(i = 0;i <= 3;i++) /* update rotHist */
- {
- for(j = 0;j <= 3;j++)
- {
- (**w_objs_hndl).object[index].rotHist[i][j].rotElem = rRotMat[i][j];
- }
- }
- /*********************** update _3dPt[i] ***********************/
- for(i = 0; i <= limit; i++)
- {
- vector[0] = (**w_objs_hndl).object[index]._3dPtH[i].x_point;
- vector[1] = (**w_objs_hndl).object[index]._3dPtH[i].y_point;
- vector[2] = (**w_objs_hndl).object[index]._3dPtH[i].z_point;
-
-
-
- for(j = 0;j<=3;j++)
- {
- newVect[j] = 0;
- }
- for(j = 0;j <= 3;j++) /* row of matrix */
- {
- for(k = 0;k <= 3;k++)
- {
- newVect[j] += (**w_objs_hndl).object[index].rotHist[j][k].rotElem * vector[k];
- }
- }
- for(j = 0;j<=3;j++)
- {
- vector[j] = newVect[j];
- }
- (**w_objs_hndl).object[index]._3dPt[i].x_point = ceil(vector[0]);
- (**w_objs_hndl).object[index]._3dPt[i].y_point = ceil(vector[1]);
- (**w_objs_hndl).object[index]._3dPt[i].z_point = ceil(vector[2]);
- }
-
- /******************* end of update _3dPt[i] ********************/
-
- if(FrontWindow() != lastPtr)
- {
- GetPort(&oldPort);
- SetPort(lastPtr);
- notFront = TRUE;
- }
- offset = (**w_objs_hndl).scrollAmount;
- obj_rect = (**w_objs_hndl).object[index].bounds;
- OffsetRect(&obj_rect, -offset.h, -offset.v);
-
- EraseRect(&obj_rect);
- InvalRect(&obj_rect);
- minX = (**w_objs_hndl).object[index]._3dPt[0].x_point; /* both are longs */
- maxX = (**w_objs_hndl).object[index]._3dPt[0].x_point;
- minY = (**w_objs_hndl).object[index]._3dPt[0].y_point;
- maxY = (**w_objs_hndl).object[index]._3dPt[0].y_point;
- /* switch(the_object.type)*/
- /* {*/
- /* case 4:*/
- /* limit = 7;*/
- /* break;*/
- /* case 5:*/
- /* limit = 17;*/
- /* break;*/
- /* }*/
-
- for(i = 1; i <= limit; i++)
- {
- tempX = (**w_objs_hndl).object[index]._3dPt[i].x_point;
- tempY = (**w_objs_hndl).object[index]._3dPt[i].y_point;
- if(tempX < minX)
- {
- minX = tempX;
- }
- if(tempX > maxX)
- {
- maxX = tempX;
- }
- if(tempY < minY)
- {
- minY = tempY;
- }
- if(tempY > maxY)
- {
- maxY = tempY;
- }
- }
- SetRect(&(**w_objs_hndl).object[index].bounds,minX,minY,maxX+1,maxY+1);
- InvalRect(&(**w_objs_hndl).object[index].bounds);
- if(notFront)
- {
- SetPort(oldPort);
- notFront = FALSE;
- }
- /***************** experimental modification *****************/
- /*draw_object(wPtr,index);*/
- do_update(wPtr);
- /*do_spec_update(wPtr,index);*/
- /************** end of experimental modification *************/
- }
- }
- }
-
- /************************* Do_Movement ***************************/
- void Do_Movement(WindowPtr wPtr,double_t delX,double_t delY,double_t delZ,Boolean useCalc)
- /* when coming from a mouseclick in */
- /* gRotateBox, wPtr is LastPtr */
- {
- Boolean spec;
- Point offset;
- Rect obj_rect;
- short myItemHit;
- short index;
- short i,j,k,n;
- short limit,obj_limit;
- short resultRow;
- short resultCol;
- short sourceCol;
- short yBase;
- short xBase;
- short zBase;
- short yNum;
- short xNum;
- short zNum;
- short _left,_top,_right,_bottom;
-
- long minX,maxX,minY,maxY,minZ,maxZ;
- long tempX,tempY,tempZ;
- long newX,newY,newZ;
- WObjsHandle w_objs_hndl;
- objectDescr the_object;
-
- double_t transMat[4][4];
- double_t rotMat[4][4];
- double_t rRotMat[4][4];
-
- double_t vector[4];
- double_t newVect[4];
-
- double_t sinX,cosX,sinY,cosY,sinZ,cosZ;
-
- GrafPtr oldPort;
- Boolean notFront;
-
- if(FrontWindow() != lastPtr)
- {
- GetPort(&oldPort);
- SetPort(lastPtr);
- InvalRect(&lastPtr->portRect);
- notFront = TRUE;
- }
- else InvalRect(&lastPtr->portRect);
-
- for(i = 0;i <= 3;i++)
- {
- for(j = 0;j <= 3;j++)
- {
- if(i == j)
- {
- transMat[i][j] = 1;
- rotMat[i][j] = 1;
- }
- else
- {
- transMat[i][j] = 0;
- rotMat[i][j] = 0;
- }
- }
- }
- vector[3] = 1;
-
- if(delX == 0 && delY == 0 && delZ == 0)
- {
- return;
- }
-
- if(delX != 0)
- {
- GetSinCos(delX,&sinX,&cosX);
- rotMat[1][1] = cosX;
- rotMat[1][2] = sinX;
- rotMat[2][1] = -sinX;
- rotMat[2][2] = cosX;
- }
- else if(delY != 0)
- {
- //#ifdef testPrey
- // delY = -180;
- //#endif
- GetSinCos(delY,&sinY,&cosY);
- rotMat[0][0] = cosY;
- rotMat[0][2] = sinY;
- rotMat[2][0] = -sinY;
- rotMat[2][2] = cosY;
- }
- else if(delZ != 0)
- {
- GetSinCos(delZ,&sinZ,&cosZ);
- rotMat[0][0] = cosZ;
- rotMat[0][1] = sinZ;
- rotMat[1][0] = -sinZ;
- rotMat[1][1] = cosZ;
- }
-
- w_objs_hndl = (WObjsHandle)GetWRefCon(wPtr);
-
- HLock((Handle)w_objs_hndl);
-
- /* *---------------------------------------- long */
- /* | *------- long */
- /* | | */
- /* v v */
- newX = (**w_objs_hndl).gXYZplane.x_point; //minX + (maxX - minX)/2;
- newY = (**w_objs_hndl).gXYZplane.y_point; //minY + (maxY - minY)/2;
- newZ = (**w_objs_hndl).gXYZplane.z_point; //minZ + (maxZ - minZ)/2;
- (**w_objs_hndl).gXYZplane.no_point = 1; /* this may be redundant */
-
-
- /******** don't bother *****************
-
- for(n = 0;n <= 15;n++)
- {
- minX = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].x_point;
- maxX = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].x_point;
- minY = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].y_point;
- maxY = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].y_point;
- minZ = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].z_point;
- maxZ = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].z_point;
-
- limit = (**w_objs_hndl).bg_object[n].max_pts;
-
- for(i = 1; i < limit; i++)
- {
- tempX = (**w_objs_hndl).bg_object[n]._3dPt_BG[i].x_point;
- tempY = (**w_objs_hndl).bg_object[n]._3dPt_BG[i].y_point;
- tempZ = (**w_objs_hndl).bg_object[n]._3dPt_BG[i].z_point;
- if(tempX < minX)
- {
- minX = tempX;
- }
- if(tempX > maxX)
- {
- maxX = tempX;
- }
- if(tempY < minY)
- {
- minY = tempY;
- }
- if(tempY > maxY)
- {
- maxY = tempY;
- }
- if(tempZ < minZ)
- {
- minZ = tempZ;
- }
- if(tempZ > maxZ)
- {
- maxZ = tempZ;
- }
- }
- SetRect(&(**w_objs_hndl).bg_object[n].bounds,minX-1,minY-1,maxX+1,maxY+1);
- InvalRect(&(**w_objs_hndl).bg_object[n].bounds);
- EraseRect(&(**w_objs_hndl).bg_object[n].bounds);
- }
-
- ************ end of don't bother ************/
-
- if((**w_objs_hndl).hasTargets == TRUE)
- {
- obj_limit = 21;
-
- /************
-
- for(n = 16;n <= 21;n++)
- {
- _left = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].x_point;
- _top = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].y_point;
- _right = _left + 32;
- _bottom = _top + 32;
- SetRect(&(**w_objs_hndl).bg_object[n].bounds,_left,_top,_right,_bottom);
- InvalRect(&(**w_objs_hndl).bg_object[n].bounds);
- EraseRect(&(**w_objs_hndl).bg_object[n].bounds);
- }
-
- ******************/
- }
- else obj_limit = 15;
-
-
-
- //minX = (**w_objs_hndl).object[index].bounds.left/* - offset.h*/;
- //maxX = (**w_objs_hndl).object[index].bounds.right/* - offset.h*/;
- //minY = (**w_objs_hndl).object[index].bounds.top/* - offset.v*/;
- //maxY = (**w_objs_hndl).object[index].bounds.bottom/* - offset.v*/;
-
- HUnlock((Handle)w_objs_hndl);
-
- if(delX != 0)
- {
- rotMat[1][3] = newY * (1 - cosX) - newZ * sinX;
- rotMat[2][3] = newZ * (1 - cosX) + newY * sinX;
- }
- else if(delY != 0)
- {
- rotMat[0][3] = newX * (1 - cosY) - newZ * sinY;
- rotMat[2][3] = newZ * (1 - cosY) + newX * sinY;
- }
- else if(delZ != 0)
- {
- rotMat[0][3] = newX * (1 - cosZ) - newY * sinZ;
- rotMat[1][3] = newY * (1 - cosZ) + newX * sinZ;
- }
-
-
- for(n = 0;n <= obj_limit;n++)
- {
- for(i = 0;i <= 3;i++) /* initialize rRotMat */
- {
- for(j = 0;j <= 3;j++)
- {
- rRotMat[i][j] = 0;
- }
- }
- for(i = 0;i <= 3;i++)
- {
- for(j = 0;j <= 3;j++)
- {
- for(k = 0;k <= 3;k++)
- {
- rRotMat[i][j] += rotMat[i][k] * (**w_objs_hndl).bg_object[n].rotHist[k][j].rotElem;
- }
- }
- }
- for(i = 0;i <= 3;i++) /* update rotHist */
- {
- for(j = 0;j <= 3;j++)
- {
- (**w_objs_hndl).bg_object[n].rotHist[i][j].rotElem = rRotMat[i][j];
- }
- }
- }
-
- /*********************** update _3dPt[i] ***********************/
- for(n = 0;n <= obj_limit;n++)
- {
- limit = (**w_objs_hndl).bg_object[n].max_pts;
-
- for(i = 0; i < limit; i++)
- {
- vector[0] = (**w_objs_hndl).bg_object[n]._3dPtH_BG[i].x_point;
- vector[1] = (**w_objs_hndl).bg_object[n]._3dPtH_BG[i].y_point;
- vector[2] = (**w_objs_hndl).bg_object[n]._3dPtH_BG[i].z_point;
-
-
-
- for(j = 0;j <= 3;j++)
- {
- newVect[j] = 0;
- }
- for(j = 0;j <= 3;j++) /* row of matrix */
- {
- for(k = 0;k <= 3;k++)
- {
- newVect[j] += (**w_objs_hndl).bg_object[n].rotHist[j][k].rotElem * vector[k];
- }
- }
- for(j = 0;j <= 3;j++)
- {
- vector[j] = newVect[j];
- }
- (**w_objs_hndl).bg_object[n]._3dPt_BG[i].x_point = ceil(vector[0]);
- (**w_objs_hndl).bg_object[n]._3dPt_BG[i].y_point = ceil(vector[1]);
- (**w_objs_hndl).bg_object[n]._3dPt_BG[i].z_point = ceil(vector[2]);
- }
- }
- /******************* end of update _3dPt[i] ********************/
-
- offset = (**w_objs_hndl).scrollAmount;
- //obj_rect = (**w_objs_hndl).object[index].bounds;
- //OffsetRect(&obj_rect, -offset.h, -offset.v);
-
- //EraseRect(&obj_rect);
- //InvalRect(&obj_rect);
-
- /***********************
-
- for(n = 0;n <= 15;n++)
- {
- minX = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].x_point;
- maxX = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].x_point;
- minY = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].y_point;
- maxY = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].y_point;
-
- limit = (**w_objs_hndl).bg_object[n].max_pts;
-
- for(i = 1; i < limit; i++)
- {
- tempX = (**w_objs_hndl).bg_object[n]._3dPt_BG[i].x_point;
- tempY = (**w_objs_hndl).bg_object[n]._3dPt_BG[i].y_point;
- if(tempX < minX)
- {
- minX = tempX;
- }
- if(tempX > maxX)
- {
- maxX = tempX;
- }
- if(tempY < minY)
- {
- minY = tempY;
- }
- if(tempY > maxY)
- {
- maxY = tempY;
- }
- }
- SetRect(&(**w_objs_hndl).bg_object[n].bounds,minX,minY,maxX+1,maxY+1);
- //InvalRect(&(**w_objs_hndl).bg_object[n].bounds);
- //EraseRect(&(**w_objs_hndl).bg_object[n].bounds); why doing this again?
- }
-
-
-
- if((**w_objs_hndl).hasTargets == TRUE)
- {
- for(n = 16;n <= 21;n++)
- {
- _left = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].x_point;
- _top = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].y_point;
- _right = _left + 32;
- _bottom = _top + 32;
- SetRect(&(**w_objs_hndl).bg_object[n].bounds,_left,_top,_right,_bottom);
- //InvalRect(&(**w_objs_hndl).bg_object[n].bounds);
- //EraseRect(&(**w_objs_hndl).bg_object[n].bounds); seems to be erasing the place to where the new position is to be drawn
- }
- }
-
- *******************/
-
- if(notFront)
- {
- SetPort(oldPort);
- notFront = FALSE;
- }
- /***************** experimental modification *****************/
- /*draw_object(wPtr,index);*/
- do_update(wPtr); /* in calc_update.c */
- /*do_spec_update(wPtr,index);*/
- /************** end of experimental modification *************/
- }
-
- /************************ Do_Translation *************************/
- void Do_Translation(WindowPtr wPtr,double_t delX,double_t delY,double_t delZ,Boolean useCalc)
- /* when coming from a mouseclick in */
- /* gRotateBox, wPtr is LastPtr */
- {
- short i,n;
- short limit;
- long minX,maxX,minY,maxY,minZ,maxZ;
- long tempX,tempY,tempZ;
- WObjsHandle w_objs_hndl;
- objectDescr the_object;
- GrafPtr oldPort;
- Boolean notFront;
-
- w_objs_hndl = (WObjsHandle)GetWRefCon(wPtr);
-
-
- if(FrontWindow() != lastPtr)
- {
- GetPort(&oldPort);
- SetPort(lastPtr);
- InvalRect(&lastPtr->portRect);
- notFront = TRUE;
- }
- else InvalRect(&lastPtr->portRect);
- /**************************************
-
-
- for(n = 0;n <= 15;n++)
- {
-
- minX = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].x_point;
- maxX = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].x_point;
- minY = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].y_point;
- maxY = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].y_point;
-
- limit = (**w_objs_hndl).bg_object[n].max_pts;
-
- for(i = 1; i < limit; i++)
- {
- tempX = (**w_objs_hndl).bg_object[n]._3dPt_BG[i].x_point; /* both longs *//*
- tempY = (**w_objs_hndl).bg_object[n]._3dPt_BG[i].y_point;
-
- (**w_objs_hndl).bg_object[n]._3dPt_BG[i].z_point += delZ;
-
- if(tempX < minX)
- {
- minX = tempX;
- }
- if(tempX > maxX)
- {
- maxX = tempX;
- }
- if(tempY < minY)
- {
- minY = tempY;
- }
- if(tempY > maxY)
- {
- maxY = tempY;
- }
- }
- SetRect(&(**w_objs_hndl).bg_object[n].bounds,minX-1,minY-1,maxX+1,maxY+1);
- InvalRect(&(**w_objs_hndl).bg_object[n].bounds);
- EraseRect(&(**w_objs_hndl).bg_object[n].bounds);
- }
-
- **************/
-
- /*************************************************************************
-
-
- minX = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].x_point;
- maxX = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].x_point;
- minY = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].y_point;
- maxY = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].y_point;
-
- for(i = 1; i < limit; i++)
- {
- tempX = (**w_objs_hndl).bg_object[n]._3dPt_BG[i].x_point;
- tempY = (**w_objs_hndl).bg_object[n]._3dPt_BG[i].y_point;
- if(tempX < minX)
- {
- minX = tempX;
- }
- if(tempX > maxX)
- {
- maxX = tempX;
- }
- if(tempY < minY)
- {
- minY = tempY;
- }
- if(tempY > maxY)
- {
- maxY = tempY;
- }
- }
- SetRect(&(**w_objs_hndl).bg_object[n].bounds,minX,minY,maxX+1,maxY+1);
- EraseRect(&(**w_objs_hndl).bg_object[n].bounds);
- InvalRect(&(**w_objs_hndl).bg_object[n].bounds);
- *************************************************************************/
- if(notFront)
- {
- SetPort(oldPort);
- notFront = FALSE;
- }
- /***************** experimental modification *****************/
- /*draw_object(wPtr,index);*/
- do_update(wPtr);
- /*do_spec_update(wPtr,index);*/
- /************** end of experimental modification *************/
- }
-
- /*********************** Do_Plane_Control ************************/
- void Do_Plane_Control(WindowPtr wPtr,double_t delX,double_t delY,double_t delZ,Boolean useCalc)
- {
- Boolean spec;
- Point offset;
- Rect obj_rect;
- short myItemHit;
- short index;
- short i,j,k,n;
- short limit,obj_limit;
- short resultRow;
- short resultCol;
- short sourceCol;
- short yBase;
- short xBase;
- short zBase;
- short yNum;
- short xNum;
- short zNum;
- short _left,_top,_right,_bottom;
- short houseN;
-
- long minX,maxX,minY,maxY,minZ,maxZ;
- long tempX,tempY,tempZ;
- long newX,newY,newZ;
- WObjsHandle w_objs_hndl;
- objectDescr the_object;
-
- double_t transMat[4][4];
- double_t rotMat[4][4];
- double_t rRotMat[4][4];
-
- double_t vector[4];
- double_t newVect[4];
-
- double_t sinX,cosX,sinY,cosY,sinZ,cosZ;
-
- GrafPtr oldPort;
- Boolean notFront;
-
- w_objs_hndl = (WObjsHandle)GetWRefCon(wPtr);
- if((**w_objs_hndl).isPrey == 1)
- {
- if(preyPtr != NIL)
- {
- if(FrontWindow() != preyPtr)
- {
- GetPort(&oldPort);
- SetPort(preyPtr);
- InvalRect(&preyPtr->portRect);
- notFront = TRUE;
- }
- else
- {
- InvalRect(&preyPtr->portRect);
- notFront = FALSE;
- }
- }
- else
- {
- GetPort(&oldPort);
- SetPort(wPtr);
- InvalRect(&wPtr->portRect);
- }
- }
- else
- {
- if(FrontWindow() != lastPtr)
- {
- GetPort(&oldPort);
- SetPort(lastPtr);
- InvalRect(&lastPtr->portRect);
- notFront = TRUE;
- }
- else
- {
- InvalRect(&lastPtr->portRect);
- notFront = FALSE;
- }
- }
- for(i = 0;i <= 3;i++) /* initialize transMat & rotMat */
- {
- for(j = 0;j <= 3;j++)
- {
- if(i == j)
- {
- transMat[i][j] = 1;
- rotMat[i][j] = 1;
- }
- else
- {
- transMat[i][j] = 0;
- rotMat[i][j] = 0;
- }
- }
- }
- vector[3] = 1;
-
- if(delX == 0 && delY == 0 && delZ == 0)
- {
- return;
- }
-
- if(delX != 0)
- {
- GetSinCos(delX,&sinX,&cosX);
- rotMat[1][1] = cosX;
- rotMat[1][2] = sinX;
- rotMat[2][1] = -sinX;
- rotMat[2][2] = cosX;
- }
- else if(delY != 0)
- {
- GetSinCos(delY,&sinY,&cosY);
- rotMat[0][0] = cosY;
- rotMat[0][2] = sinY;
- rotMat[2][0] = -sinY;
- rotMat[2][2] = cosY;
- }
- else if(delZ != 0)
- {
- GetSinCos(delZ,&sinZ,&cosZ);
- rotMat[0][0] = cosZ;
- rotMat[0][1] = sinZ;
- rotMat[1][0] = -sinZ;
- rotMat[1][1] = cosZ;
- }
-
- //w_objs_hndl = (WObjsHandle)GetWRefCon(wPtr);
-
- HLock((Handle)w_objs_hndl);
-
- n = 0;
- while((**w_objs_hndl).object[n].armed == FALSE) n++;
-
-
- newX = (**w_objs_hndl).object[n]._3dPtH[7].x_point; //minX + (maxX - minX)/2;
- newY = (**w_objs_hndl).object[n]._3dPtH[7].y_point; //minY + (maxY - minY)/2;
- newZ = -100; //minZ + (maxZ - minZ)/2;
- (**w_objs_hndl).gXYZplane.no_point = 1;
- houseN = n;
- /********************************
-
-
- for(n = 0;n <= 15;n++)
- {
- minX = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].x_point;
- maxX = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].x_point;
- minY = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].y_point;
- maxY = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].y_point;
- minZ = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].z_point;
- maxZ = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].z_point;
-
- limit = (**w_objs_hndl).bg_object[n].max_pts;
-
- for(i = 1; i < limit; i++)
- {
- tempX = (**w_objs_hndl).bg_object[n]._3dPt_BG[i].x_point;
- tempY = (**w_objs_hndl).bg_object[n]._3dPt_BG[i].y_point;
- tempZ = (**w_objs_hndl).bg_object[n]._3dPt_BG[i].z_point;
- if(tempX < minX)
- {
- minX = tempX;
- }
- if(tempX > maxX)
- {
- maxX = tempX;
- }
- if(tempY < minY)
- {
- minY = tempY;
- }
- if(tempY > maxY)
- {
- maxY = tempY;
- }
- if(tempZ < minZ)
- {
- minZ = tempZ;
- }
- if(tempZ > maxZ)
- {
- maxZ = tempZ;
- }
- }
- SetRect(&(**w_objs_hndl).bg_object[n].bounds,minX-1,minY-1,maxX+1,maxY+1);
- InvalRect(&(**w_objs_hndl).bg_object[n].bounds);
- EraseRect(&(**w_objs_hndl).bg_object[n].bounds);
- }
-
- *********************/
-
-
- if((**w_objs_hndl).hasTargets == TRUE)
- {
- obj_limit = 21;
- /*****************
-
- for(n = 16;n <= 21;n++)
- {
- _left = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].x_point;
- _top = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].y_point;
- _right = _left + 32;
- _bottom = _top + 32;
- SetRect(&(**w_objs_hndl).bg_object[n].bounds,_left,_top,_right,_bottom);
- InvalRect(&(**w_objs_hndl).bg_object[n].bounds);
- EraseRect(&(**w_objs_hndl).bg_object[n].bounds);
- }
-
- ***************/
-
- }
- else obj_limit = 15;
-
-
-
- //minX = (**w_objs_hndl).object[index].bounds.left/* - offset.h*/;
- //maxX = (**w_objs_hndl).object[index].bounds.right/* - offset.h*/;
- //minY = (**w_objs_hndl).object[index].bounds.top/* - offset.v*/;
- //maxY = (**w_objs_hndl).object[index].bounds.bottom/* - offset.v*/;
-
- HUnlock((Handle)w_objs_hndl);
-
- if(delX != 0)
- {
- rotMat[1][3] = newY * (1 - cosX) - newZ * sinX;
- rotMat[2][3] = newZ * (1 - cosX) + newY * sinX;
- }
- else if(delY != 0)
- {
- rotMat[0][3] = newX * (1 - cosY) - newZ * sinY;
- rotMat[2][3] = newZ * (1 - cosY) + newX * sinY;
- }
- else if(delZ != 0)
- {
- rotMat[0][3] = newX * (1 - cosZ) - newY * sinZ;
- rotMat[1][3] = newY * (1 - cosZ) + newX * sinZ;
- }
-
-
- for(n = 0;n <= obj_limit;n++)
- {
- for(i = 0;i <= 3;i++) /* initialize rRotMat */
- {
- for(j = 0;j <= 3;j++)
- {
- rRotMat[i][j] = 0;
- }
- }
- for(i = 0;i <= 3;i++)
- {
- for(j = 0;j <= 3;j++)
- {
- for(k = 0;k <= 3;k++)
- {
- rRotMat[i][j] += rotMat[i][k] * (**w_objs_hndl).bg_object[n].rotHist[k][j].rotElem;
- }
- }
- }
- for(i = 0;i <= 3;i++) /* update rotHist */
- {
- for(j = 0;j <= 3;j++)
- {
- (**w_objs_hndl).bg_object[n].rotHist[i][j].rotElem = rRotMat[i][j];
- }
- }
- }
-
- if((**w_objs_hndl).isPrey == 1)
- {
- n = houseN;
- for(i = 0; i < 21; i++)
- {
- vector[0] = (**w_objs_hndl).object[n]._3dPtH[i].x_point;
- vector[1] = (**w_objs_hndl).object[n]._3dPtH[i].y_point;
- vector[2] = (**w_objs_hndl).object[n]._3dPtH[i].z_point;
-
- for(j = 0;j <= 3;j++)
- {
- newVect[j] = 0;
- }
-
- for(j = 0;j <= 3;j++) /* row of matrix */
- {
- for(k = 0;k <= 3;k++)
- {
- newVect[j] += (**w_objs_hndl).object[n].rotHist[j][k].rotElem * vector[k];
- }
- }
-
- for(j = 0;j <= 3;j++)
- {
- vector[j] = newVect[j];
- }
- (**w_objs_hndl).object[n]._3dPt[i].x_point = ceil(vector[0]);
- (**w_objs_hndl).object[n]._3dPt[i].y_point = ceil(vector[1]);
- (**w_objs_hndl).object[n]._3dPt[i].z_point = ceil(vector[2]);
- }
- }
- /*********************** update _3dPt[i] ***********************/
- for(n = 0;n <= obj_limit;n++)
- {
- limit = (**w_objs_hndl).bg_object[n].max_pts;
-
- for(i = 0; i < limit; i++)
- {
- vector[0] = (**w_objs_hndl).bg_object[n]._3dPtH_BG[i].x_point;
- vector[1] = (**w_objs_hndl).bg_object[n]._3dPtH_BG[i].y_point;
- vector[2] = (**w_objs_hndl).bg_object[n]._3dPtH_BG[i].z_point;
-
-
-
- for(j = 0;j <= 3;j++)
- {
- newVect[j] = 0;
- }
- for(j = 0;j <= 3;j++) /* row of matrix */
- {
- for(k = 0;k <= 3;k++)
- {
- newVect[j] += (**w_objs_hndl).bg_object[n].rotHist[j][k].rotElem * vector[k];
- }
- }
- for(j = 0;j <= 3;j++)
- {
- vector[j] = newVect[j];
- }
- (**w_objs_hndl).bg_object[n]._3dPt_BG[i].x_point = ceil(vector[0]);
- (**w_objs_hndl).bg_object[n]._3dPt_BG[i].y_point = ceil(vector[1]);
- (**w_objs_hndl).bg_object[n]._3dPt_BG[i].z_point = ceil(vector[2]);
- }
- }
- /******************* end of update _3dPt[i] ********************/
-
- offset = (**w_objs_hndl).scrollAmount;
- //obj_rect = (**w_objs_hndl).object[index].bounds;
- //OffsetRect(&obj_rect, -offset.h, -offset.v);
-
- //EraseRect(&obj_rect);
- //InvalRect(&obj_rect);
-
- /************************
-
- for(n = 0;n <= 15;n++)
- {
- minX = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].x_point;
- maxX = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].x_point;
- minY = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].y_point;
- maxY = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].y_point;
-
- limit = (**w_objs_hndl).bg_object[n].max_pts;
-
- for(i = 1; i < limit; i++)
- {
- tempX = (**w_objs_hndl).bg_object[n]._3dPt_BG[i].x_point;
- tempY = (**w_objs_hndl).bg_object[n]._3dPt_BG[i].y_point;
- if(tempX < minX)
- {
- minX = tempX;
- }
- if(tempX > maxX)
- {
- maxX = tempX;
- }
- if(tempY < minY)
- {
- minY = tempY;
- }
- if(tempY > maxY)
- {
- maxY = tempY;
- }
- }
- SetRect(&(**w_objs_hndl).bg_object[n].bounds,minX,minY,maxX+1,maxY+1);
- //InvalRect(&(**w_objs_hndl).bg_object[n].bounds);
- //EraseRect(&(**w_objs_hndl).bg_object[n].bounds);
- }
-
- *****************/
- /*******************
-
- if((**w_objs_hndl).hasTargets == TRUE)
- {
- for(n = 16;n <= 21;n++)
- {
- _left = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].x_point;
- _top = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].y_point;
- _right = _left + 32;
- _bottom = _top + 32;
- SetRect(&(**w_objs_hndl).bg_object[n].bounds,_left,_top,_right,_bottom);
- //InvalRect(&(**w_objs_hndl).bg_object[n].bounds);
- //EraseRect(&(**w_objs_hndl).bg_object[n].bounds);
- }
- }
-
- ********************/
-
- if(notFront)
- {
- SetPort(oldPort);
- notFront = FALSE;
- }
-
- /***************** experimental modification *****************/
- /*draw_object(wPtr,index);*/
- do_update(wPtr);
- /*do_spec_update(wPtr,index);*/
- /************** end of experimental modification *************/
- }
-
-
- /*********************** MatrixTimesVector ***********************/
- //void MatrixTimesVector(mat,vect)
- void MatrixTimesVector(double_t mat[4][4], double_t *vect[])
- {
- short i,j;
- double_t newVect[4];
-
- for(i = 0;i<=3;i++)
- {
- newVect[i] = 0;
- }
- for(i = 0;i <= 3;i++) /* row of matrix */
- {
- for(j = 0;j <= 3;j++)
- {
- newVect[i] += mat[i][j] * *vect[j];
- }
- }
- for(i = 0;i<=3;i++)
- {
- *vect[i] = newVect[i];
- }
- }
- /******************** end of MatrixTimesVector *******************/
-
- /**************************** SinCos *****************************/
- void GetSinCos(double_t delQ,double_t *sinQ,double_t *cosQ)
- //double delQ;
- //double *sinQ;
- //double *cosQ;
- {
- double_t temp,temp1,sinsqrd,dif;
- //extended result,result1;
- double_t result,result1;
-
- /************ sin ************/
- temp1 = (delQ/360) * 2 * 3.141592654;
- //x96tox80(&temp1,&result1);
- //result = sin(result1); /* result is sin in extended format */
- result = sin(temp1); /* result is sin in extended format */
- //x80tox96(&result,&temp);
- //*sinQ = temp;
- *sinQ = result;
-
- /************ cos ************/
-
- //sinsqrd = temp * temp;
- sinsqrd = result * result;
- dif = 1 - sinsqrd;
- //x96tox80(&dif,&result1);
- //result = sqrt(result1);
- result = sqrt(dif);
- //x80tox96(&result,&temp);
- //*cosQ = temp;
- *cosQ = result;
-
- /* temp1 = (delQ/360) * 2 * 3.141592654;*/
- /* x96tox80(&temp1,&result1);*/
- /* result = cos(result1);*/
- /* x80tox96(&result,&temp);*/
- /* *cosQ = temp;*/
-
- }
- /************************* end of SinCos *************************/
-
- /************************** MatTimesMat **************************/
- //void MatTimesMat(rotMat,oRotMat,/*rRotMat*/qRotMat)
- void MatTimesMat(double_t rotMat[4][4],double_t oRotMat[4][4],/*rRotMat*/double_t *qRotMat[])
- //double rotMat[4][4];
- //double oRotMat[4][4];
- /*double *rRotMat[4][4];*/
- //double *qRotMat[];
- {
- short i,j,k;
- double_t rRotMat[4][4];
- double_t tempRotArray[16];
-
- for(i = 0;i <= 3;i++)
- {
- for(j = 0;j <= 3;j++)
- {
- rRotMat[i][j] = 0;
- }
- }
- for(i = 0;i <= 3;i++)
- {
- for(j = 0;j <= 3;j++)
- {
- for(k = 0;k <= 3;k++)
- {
- rRotMat[i][j] += rotMat[i][k] * oRotMat[k][j];
- }
- }
- }
- /**************** temp soln to problem ***************************/
- for(i = 0;i <= 15;i++)
- {
- tempRotArray[i] = rRotMat[i%4][i/4];
- }
- for(i = 0;i <= 15;i++)
- {
- *qRotMat[i] = tempRotArray[i];
- }
- /************* end of temp soln to problem ***********************/
- }
-
- /*************************** FireGuns ****************************/
- void FireGuns(long *innerSel,long *outerSel)
- {
- SndChannelPtr Chan00,Chan01,Chan02,Chan03,Chan04,Chan05,Chan06,Chan07,Chan08,Chan09;
- long init;
- short i,synth = 5;
- OSErr errCode,iErr;
- /* cw5 */ //
- SndListHandle guns00,guns01,guns02,guns03,guns04,guns05,guns06,guns07,guns08,guns09,missle,razz;
- Boolean quietNow = 0;
- long dummy,start,start1,stop1,start2,stop2,ET,ET1,ET2;
- WObjsHandle w_objs_hndl;
- Point thePt;
- short n,mCount;
- WindowPtr save_port;
-
- w_objs_hndl = (WObjsHandle)GetWRefCon(lastPtr);
-
- GetPort(&save_port);
- SetPort(lastPtr);
-
- n = 0;
- while((**w_objs_hndl).object[n].armed == FALSE) n++;
-
- switch((**w_objs_hndl).arms_selected)
- {
- case 0:
- Chan00 = (SndChannelPtr)NewPtrClear(sizeof(SndChannel));
- if(Chan00 != nil)
- {
- Chan00->qLength = stdQLength;
- iErr = SndNewChannel(&Chan00,sampledSynth,initMono,nil);
- }
- Chan01 = (SndChannelPtr)NewPtrClear(sizeof(SndChannel));
- if(Chan01 != nil)
- {
- Chan01->qLength = stdQLength;
- iErr = SndNewChannel(&Chan01,sampledSynth,initMono,nil);
- }
- Chan02 = (SndChannelPtr)NewPtrClear(sizeof(SndChannel));
- if(Chan02 != nil)
- {
- Chan02->qLength = stdQLength;
- iErr = SndNewChannel(&Chan02,sampledSynth,initMono,nil);
- }
- Chan03 = (SndChannelPtr)NewPtrClear(sizeof(SndChannel));
- if(Chan03 != nil)
- {
- Chan03->qLength = stdQLength;
- iErr = SndNewChannel(&Chan03,sampledSynth,initMono,nil);
- }
- Chan04 = (SndChannelPtr)NewPtrClear(sizeof(SndChannel));
- if(Chan04 != nil)
- {
- Chan04->qLength = stdQLength;
- iErr = SndNewChannel(&Chan04,sampledSynth,initMono,nil);
- }
- Chan05 = (SndChannelPtr)NewPtrClear(sizeof(SndChannel));
- if(Chan05 != nil)
- {
- Chan05->qLength = stdQLength;
- iErr = SndNewChannel(&Chan05,sampledSynth,initMono,nil);
- }
- Chan06 = (SndChannelPtr)NewPtrClear(sizeof(SndChannel));
- if(Chan06 != nil)
- {
- Chan06->qLength = stdQLength;
- iErr = SndNewChannel(&Chan06,sampledSynth,initMono,nil);
- }
- Chan07 = (SndChannelPtr)NewPtrClear(sizeof(SndChannel));
- if(Chan07 != nil)
- {
- Chan07->qLength = stdQLength;
- iErr = SndNewChannel(&Chan07,sampledSynth,initMono,nil);
- }
- Chan08 = (SndChannelPtr)NewPtrClear(sizeof(SndChannel));
- if(Chan08 != nil)
- {
- Chan08->qLength = stdQLength;
- iErr = SndNewChannel(&Chan08,sampledSynth,initMono,nil);
- }
- Chan09 = (SndChannelPtr)NewPtrClear(sizeof(SndChannel));
- if(Chan09 != nil)
- {
- Chan09->qLength = stdQLength;
- iErr = SndNewChannel(&Chan09,sampledSynth,initMono,nil);
- }
- /************************/
- /* cw5 */ //guns00 = GetResource ('snd ', 1200);
-
- //if (guns00 != NULL)
- //{
- // Delay(0L,&start);
- // for(i = 0;i <=9;i++)
- // {
- // errCode = SndPlay ((**w_objs_hndl).object[n].sndStruct[i].Chan00, guns00, true); //errCode = SndPlay (NULL, guns0, false);
- // Delay(3L,&dummy);
- // }
- /******************************/
-
- // errCode = SndPlay ((**w_objs_hndl).object[n].sndStruct[i].Chan01, guns00, true); /* true means asynchronous */
- /******************************
- Delay(10L,&dummy);
-
- errCode = SndPlay ((**w_objs_hndl).object[n].sndStruct[i].Chan02, guns00, true);
- Delay(3L,&dummy);
-
- errCode = SndPlay (Chan03, guns00, true);
- Delay(3L,&dummy);
-
- errCode = SndPlay (Chan04, guns00, true);
- Delay(3L,&dummy);
-
- errCode = SndPlay (Chan05, guns00, true);
- Delay(3L,&dummy);
-
- errCode = SndPlay (Chan06, guns00, true);
- Delay(3L,&dummy);
-
- errCode = SndPlay (Chan07, guns00, true);
- Delay(3L,&dummy);
-
- errCode = SndPlay (Chan08, guns00, true);
- Delay(3L,&dummy);
-
- errCode = SndPlay (Chan09, guns00, true);
- Delay(3L,&dummy);
- ****************************************************/
- //Delay(0L,&stop);
- //ET = stop - start;
- //ET1 = stop1 - start1;
- //ET2 = stop2 - start2;
- //}
- /***************************************************
- iErr = SndDisposeChannel(Chan01,quietNow);
- iErr = SndDisposeChannel(Chan02,quietNow);
- iErr = SndDisposeChannel(Chan03,quietNow);
- iErr = SndDisposeChannel(Chan04,quietNow);
- iErr = SndDisposeChannel(Chan05,quietNow);
- iErr = SndDisposeChannel(Chan06,quietNow);
- iErr = SndDisposeChannel(Chan07,quietNow);
- iErr = SndDisposeChannel(Chan08,quietNow);
- iErr = SndDisposeChannel(Chan09,quietNow);
- ****************************************************/
- SetPt(&thePt,(**w_objs_hndl).object[n]._3dPtH[7].x_point,(**w_objs_hndl).object[n]._3dPtH[7].y_point);
- if (
- PtInRect(thePt,&gFirstCalcIcon) &&
- (**w_objs_hndl).bg_object[16].alive &&
- (**w_objs_hndl).bg_object[16]._3dPt_BG[0].z_point < 0
- )
- {
- EraseRect(&gFirstCalcIcon);
- InvalRect(&lastPtr->portRect);
- InvalRect(&gFirstCalcIcon);
- (**w_objs_hndl).bg_object[16].alive = FALSE;
- (**w_objs_hndl).targets_left -= 1;
- //draw_palette(lastPtr);
- do_update(lastPtr);
- }
- if (
- PtInRect(thePt,&gSecondCalcIcon) &&
- (**w_objs_hndl).bg_object[17].alive &&
- (**w_objs_hndl).bg_object[17]._3dPt_BG[0].z_point < 0
- )
- {
- EraseRect(&gSecondCalcIcon);
- InvalRect(&lastPtr->portRect);
- InvalRect(&gSecondCalcIcon);
- (**w_objs_hndl).bg_object[17].alive = FALSE;
- (**w_objs_hndl).targets_left -= 1;
- //draw_palette(lastPtr);
- do_update(lastPtr);
- }
- if (
- PtInRect(thePt,&gThirdCalcIcon) &&
- (**w_objs_hndl).bg_object[18].alive &&
- (**w_objs_hndl).bg_object[18]._3dPt_BG[0].z_point < 0
- )
- {
- EraseRect(&gThirdCalcIcon);
- InvalRect(&gThirdCalcIcon);
- InvalRect(&lastPtr->portRect);
- (**w_objs_hndl).bg_object[18].alive = FALSE;
- (**w_objs_hndl).targets_left -= 1;
- //draw_palette(lastPtr);
- do_update(lastPtr);
- }
- if (
- PtInRect(thePt,&gFourthCalcIcon) &&
- (**w_objs_hndl).bg_object[19].alive &&
- (**w_objs_hndl).bg_object[19]._3dPt_BG[0].z_point < 0
- )
- {
- EraseRect(&gFourthCalcIcon);
- InvalRect(&gFourthCalcIcon);
- InvalRect(&lastPtr->portRect);
- (**w_objs_hndl).bg_object[19].alive = FALSE;
- (**w_objs_hndl).targets_left -= 1;
- //draw_palette(lastPtr);
- do_update(lastPtr);
- }
- if (
- PtInRect(thePt,&gFifthCalcIcon) &&
- (**w_objs_hndl).bg_object[20].alive &&
- (**w_objs_hndl).bg_object[20]._3dPt_BG[0].z_point < 0
- )
- {
- EraseRect(&gFifthCalcIcon);
- InvalRect(&gFifthCalcIcon);
- InvalRect(&lastPtr->portRect);
- (**w_objs_hndl).bg_object[20].alive = FALSE;
- (**w_objs_hndl).targets_left -= 1;
- do_update(lastPtr);
- //draw_palette(lastPtr);
- }
- if (
- PtInRect(thePt,&gSixthCalcIcon) &&
- (**w_objs_hndl).bg_object[21].alive &&
- (**w_objs_hndl).bg_object[21]._3dPt_BG[0].z_point < 0
- )
- {
- /*EraseRect(&gSixthCalcIcon);
- InvalRect(&gSixthCalcIcon);
- (**w_objs_hndl).bg_object[21].alive = FALSE;
- (**w_objs_hndl).targets_left -= 1;*/
- //draw_palette(lastPtr);
- /* cw5 */ //razz = GetResource ('snd ', 403);
- //if (razz != NULL)
- //{
- // errCode = SndPlay ((**w_objs_hndl).object[n].sndStruct[0].Chan00, razz, true); //errCode = SndPlay (NULL, guns0, false);
- //}
- //do_update(lastPtr);
- }
- //iErr = SndDisposeChannel(Chan00,quietNow);
- break;
- case 1:
- mCount = (**w_objs_hndl).object[n].missles;
- if(mCount > 0)
- {
- //Chan00 = (SndChannelPtr)NewPtrClear(sizeof(SndChannel));
- //if(Chan00 != nil)
- //{
- // Chan00->qLength = stdQLength;
- // iErr = SndNewChannel(&Chan00,sampledSynth,initMono,nil);
- //}
- /* cw5 */ //missle = GetResource ('snd ', 1300);
- //if (missle != NULL)
- //{
- // errCode = SndPlay ((**w_objs_hndl).object[n].sndStruct[1].Chan00, missle, true); //errCode = SndPlay (NULL, guns0, false);
- //}
- (**w_objs_hndl).object[n].missles -= 1;
- EraseRect(&(**w_objs_hndl).object[n].mStruct[14 - mCount].mRect);
- InvalRect(&(**w_objs_hndl).object[n].mStruct[14 - mCount].mRect);
- do_update(lastPtr);
- //iErr = SndDisposeChannel(Chan00,quietNow);
- GuideMissle(innerSel,outerSel);
- }
- //TrackTarget();
- break;
- case 2:
- DarkWindowInit();
- break;
- }
- SetPort(save_port);
- }
- /*********************** end of FireGuns *************************/
-
-
- /************************* TrackTarget ***************************/
- Boolean TrackTarget(long *innerSel,long *outerSel)
- {
- WObjsHandle w_objs_hndl;
- short i,n;
- long calcX,calcY,calcZ,hseX,hseY;
- long delX,delY,delZ;
- double_t radius,hyp;
-
- w_objs_hndl = (WObjsHandle)GetWRefCon(lastPtr);
- n = 0;
- while((**w_objs_hndl).object[n].armed == FALSE) n++;
- if((**w_objs_hndl).hasTargets == TRUE)
- {
- hseX = (**w_objs_hndl).object[n]._3dPtH[7].x_point;
- hseY = (**w_objs_hndl).object[n]._3dPtH[7].y_point;
- for(i = 0;i <=5;i++)
- {
- if((**w_objs_hndl).bg_object[i+16].alive)
- {
- calcZ = (**w_objs_hndl).bg_object[i+16]._3dPt_BG[0].z_point;
- if(calcZ < 0)
- {
- calcX = (**w_objs_hndl).bg_object[i+16]._3dPt_BG[0].x_point + 16;
- calcY = (**w_objs_hndl).bg_object[i+16]._3dPt_BG[0].y_point + 16;
- delX = hseX - calcX; /* X dif of target & hse crosshairs */
- if(delX < 0) delX *= -1;
- delY = hseY - calcY; /* Y dif of target & hse crosshairs */
- if(delY < 0) delY *= -1;
- calcZ *= -1;
- radius = sqrt(delX*delX + delY*delY); /* radius is in plane of screen */
- hyp = radius/(double_t)calcZ; /* hyp is really Tan(œ) */
- if(hyp <= .5) /* if angle <= 26.5 degress */
- {
- if(hyp <= .25) switch(i) /* if angle <= 14 degress */
- {
- case 0:
- *innerSel |= 0x00000001;
- break;
- case 1:
- *innerSel |= 0x00000010;
- break;
- case 2:
- *innerSel |= 0x00000100;
- break;
- case 3:
- *innerSel |= 0x00001000;
- break;
- case 4:
- *innerSel |= 0x00010000;
- break;
- case 5:
- *innerSel |= 0x00100000;
- break;
- }
- else switch(i)
- {
- case 0:
- *outerSel |= 0x00000001;
- break;
- case 1:
- *outerSel |= 0x00000010;
- break;
- case 2:
- *outerSel |= 0x00000100;
- break;
- case 3:
- *outerSel |= 0x00001000;
- break;
- case 4:
- *outerSel |= 0x00010000;
- break;
- case 5:
- *outerSel |= 0x00100000;
- break;
- }
- }
- }
- }
- }
- }
- }
- /********************** end of TrackTarget ***********************/
-
- /************************** GuideMissle **************************/
- void GuideMissle(long *innerSel,long *outerSel)
- {
- WObjsHandle w_objs_hndl;
- long z1 = -5000;
- long z2 = -5000;
- long z3 = -5000;
- long z4 = -5000;
- long z5 = -5000;
- long z6 = -5000;
- long Tx,Ty,Tz;
- long selected;
- Boolean notDone = true;
- Boolean notYetDone = false;
- Boolean notHit,notOutOfRange;
- short mCount,n,pCount;
- PicHandle f1Missle,f2Missle,f3Missle,f4Missle,f5Missle,f6Missle;
- long dummy;
-
- w_objs_hndl = (WObjsHandle)GetWRefCon(lastPtr);
- n = 0;
- while((**w_objs_hndl).object[n].armed == FALSE) n++;
-
- if(*innerSel & 0x00000001)
- {
- z1 = (**w_objs_hndl).bg_object[16]._3dPt_BG[0].z_point;
- }
- if(*innerSel & 0x00000010)
- {
- z2 = (**w_objs_hndl).bg_object[17]._3dPt_BG[0].z_point;
- }
- if(*innerSel & 0x00000100)
- {
- z3 = (**w_objs_hndl).bg_object[18]._3dPt_BG[0].z_point;
- }
- if(*innerSel & 0x00001000)
- {
- z4 = (**w_objs_hndl).bg_object[19]._3dPt_BG[0].z_point;
- }
- if(*innerSel & 0x00010000)
- {
- z5 = (**w_objs_hndl).bg_object[20]._3dPt_BG[0].z_point;
- }
- if(*innerSel & 0x00100000)
- {
- z6 = (**w_objs_hndl).bg_object[21]._3dPt_BG[0].z_point;
- }
- selected = z1;
- if(z2 > selected) selected = z2;
- if(z3 > selected) selected = z3;
- if(z4 > selected) selected = z4;
- if(z5 > selected) selected = z5;
- if(z6 > selected) selected = z6;
-
- if(selected == z1)
- {
- Tx = (**w_objs_hndl).bg_object[16]._3dPt_BG[0].x_point;
- Ty = (**w_objs_hndl).bg_object[16]._3dPt_BG[0].y_point;
- Tz = z1;
- }
- if(selected == z2)
- {
- Tx = (**w_objs_hndl).bg_object[17]._3dPt_BG[0].x_point;
- Ty = (**w_objs_hndl).bg_object[17]._3dPt_BG[0].y_point;
- Tz = z2;
- }
- if(selected == z3)
- {
- Tx = (**w_objs_hndl).bg_object[18]._3dPt_BG[0].x_point;
- Ty = (**w_objs_hndl).bg_object[18]._3dPt_BG[0].y_point;
- Tz = z3;
- }
- if(selected == z4)
- {
- Tx = (**w_objs_hndl).bg_object[19]._3dPt_BG[0].x_point;
- Ty = (**w_objs_hndl).bg_object[19]._3dPt_BG[0].y_point;
- Tz = z4;
- }
- if(selected == z5)
- {
- Tx = (**w_objs_hndl).bg_object[20]._3dPt_BG[0].x_point;
- Ty = (**w_objs_hndl).bg_object[20]._3dPt_BG[0].y_point;
- Tz = z5;
- }
- if(selected == z6)
- {
- Tx = (**w_objs_hndl).bg_object[21]._3dPt_BG[0].x_point;
- Ty = (**w_objs_hndl).bg_object[21]._3dPt_BG[0].y_point;
- Tz = z6;
- }
-
- f1Missle = GetPicture( 131 );
- f2Missle = GetPicture( 132 );
- f3Missle = GetPicture( 129 );
- f4Missle = GetPicture( 133 );
- f5Missle = GetPicture( 134 );
- f6Missle = GetPicture( 135 );
- mCount = (**w_objs_hndl).object[n].missles;
- if(f2Missle != 0)
- {
- switch(13 - mCount)
- {
- case 0:
- case 2:
- case 4:
- case 6:
- SetRect (
- &(**w_objs_hndl).object[n].mStruct[13 - mCount].mRect,
- (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.left-5,
- (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.top+5,
- (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.right-5,
- (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.bottom+5
- );
- break;
- case 1:
- case 3:
- case 5:
- case 7:
- SetRect (
- &(**w_objs_hndl).object[n].mStruct[13 - mCount].mRect,
- (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.left+5,
- (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.top+5,
- (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.right+5,
- (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.bottom+5
- );
- break;
- case 8:
- case 9:
- case 10:
- case 11:
- case 12:
- case 13:
- SetRect (
- &(**w_objs_hndl).object[n].mStruct[13 - mCount].mRect,
- (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.left,
- (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.top+5,
- (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.right,
- (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.bottom+5
- );
- break;
- }
- DrawPicture(f2Missle,&(**w_objs_hndl).object[n].mStruct[13 - mCount].mRect);
- Delay(10,&dummy);
- EraseRect(&(**w_objs_hndl).object[n].mStruct[13 - mCount].mRect);
- //do_update(lastPtr);
- if(f1Missle != 0)
- {
- switch(13 - mCount)
- {
- case 0:
- case 2:
- case 4:
- case 6:
- SetRect (
- &(**w_objs_hndl).object[n].mStruct[13 - mCount].mRect,
- (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.left-5,
- (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.top+5,
- (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.right-5,
- (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.bottom+5
- );
- break;
- case 1:
- case 3:
- case 5:
- case 7:
- SetRect (
- &(**w_objs_hndl).object[n].mStruct[13 - mCount].mRect,
- (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.left+5,
- (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.top+5,
- (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.right+5,
- (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.bottom+5
- );
- break;
- case 8:
- case 9:
- case 10:
- case 11:
- case 12:
- case 13:
- SetRect (
- &(**w_objs_hndl).object[n].mStruct[13 - mCount].mRect,
- (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.left,
- (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.top+5,
- (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.right,
- (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.bottom+5
- );
- break;
- }
- }
-
- switch(13 - mCount)
- {
- case 0:
- case 1:
- case 2:
- case 3:
- case 4:
- case 5:
- case 6:
- case 7:
- //InsetRect(&(**w_objs_hndl).object[n].mStruct[13 - mCount].mRect,-2,-2);
- DrawPicture(f1Missle,&(**w_objs_hndl).object[n].mStruct[13 - mCount].mRect);
- break;
- case 8:
- DrawPicture(f3Missle,&(**w_objs_hndl).object[n].mStruct[13 - mCount].mRect);
- break;
- case 9:
- DrawPicture(f4Missle,&(**w_objs_hndl).object[n].mStruct[13 - mCount].mRect);
- break;
- case 10:
- DrawPicture(f5Missle,&(**w_objs_hndl).object[n].mStruct[13 - mCount].mRect);
- break;
- case 11:
- DrawPicture(f6Missle,&(**w_objs_hndl).object[n].mStruct[13 - mCount].mRect);
- break;
- case 12:
- DrawPicture(f3Missle,&(**w_objs_hndl).object[n].mStruct[13 - mCount].mRect);
- break;
- case 13:
- DrawPicture(f4Missle,&(**w_objs_hndl).object[n].mStruct[13 - mCount].mRect);
- break;
- }
- //do_update(lastPtr);
- Delay(10,&dummy);
- EraseRect(&(**w_objs_hndl).object[n].mStruct[13 - mCount].mRect);
- do_update(lastPtr);
- notHit = TRUE;
- notOutOfRange = TRUE;
- while(notHit || notOutOfRange)
- {
- /* loop */
-
- /* calculate dx,dy,dz */
- /* SetRect() */
- /* DrawPicture() */
- /* EraseRect() */
-
- /* end loop */
- notOutOfRange = FALSE;
- notHit = FALSE;
-
- }
- }
- }
- /********************** end of GuideMissle ***********************/
-